const fs = require("fs");

class VersionPlugin {
  constructor(options) {
    this.options = options;
  }

  apply(compiler) {
    compiler.hooks.emit.tapAsync("VersionPlugin", (compilation, callback) => {
      const { version } = this.options;

      const content = `export const appVersion = '${version}';`;

      fs.writeFileSync("./dist/version.js", content);

      callback();
    });
  }
}

module.exports = VersionPlugin;
